/**
 * add by yang.bo
 * 应用管理
 */
define(['module/component/views/FormView', 'module/component/views/GridView',
		'module/systemconfig/action/systemConfigAction',
		'module/systemconfig/tools/tools',
		"text!module/systemconfig/templates/systemConfigView.html"],
        function (FormView, GridView, hostAppAction, tools, templates) {
	var mainView = ngc.View.extend({
		template: ngc.compile(templates),
		events: {
			'click #queryBtn' : 'queryBtnClick',
			'click #cancelBtn' : 'cancelBtnClick'
	    },
	    _form: function(){
		      return this.getView("#form_content");
		  },
		_grid: function(){
			  return this.getView("#grid_content");
	  	},
	    queryBtnClick: function(){
	    },

	    cancelBtnClick: function(){
	    	this._form().reset();
	    	this.queryBtnClick();
	    },
	    
		render: function () {
	         this.$el.append(this.template({}));
	         this.initForm();
	         this.initGrid();
	    },
	     
	    initialize: function () {
	    	 this.render();	    	
	    },
	    
	    initWidget:function(){
	    	 $("#tabs").tabs({
	                canClose:true,
	              paging: true,
	              autoResizable:true
	            });
	    },

	    afterRender: function () {
	    	this.initWidget();
	    },
	    
	    //主机管理form表单
	    initForm: function () {	
	    	var that = this;
			var config_elements = [
					{
						id: 'province',
						label: '省份',
						type : 'select',
						editable:true,
					}, {
						id: 'unitUsage',
						label: '运营商',
						type : 'select',
						// enumCode : "unitUsage",
					}, {
					}, {
						id: 'projectName',
						label: '项目名称',
						type : 'text',
					}];
			this.setView("#form_content", new FormView({
				config : {
					elements : config_elements
				}
			}));
			
			this.getView("#form_content").on("viewRenderAfter", function() {
			})
	    },
	    //应用管理grid
	    initGrid: function (){
	    	var that = this;
			var opt = {
		        height: 300,
		        colModel: [{
		            name: 'id',
		            label: 'ID',
		            key: true,
		            hidden: true
		        }, {
		        	name: 'projectNameBak',
		        	label: '项目',
		        	width: 200
		        }, {
		        	name: 'url',
		        	label: '应用URL',
		        	formatter: function(cellval, opts, rwdat, _act) {
		        		if(rwdat.url != null && rwdat.url != ""){
		        			return "<span style='color:#0f659c'>"+rwdat.url+"</span>";
		        		}
		        		return "";
		        	},
		        }, {
		        	name: 'responsibility',
		        	label: '负责人',
		        	width: 80
		        }],
		        toolbar: [true, "bottom"]
			};
			this.setView("#grid_content", new GridView({
				config : {					
					grid : opt,
					callback:{
						onCellSelect: function(e, rowid, iCol, cellcontent){
							if (iCol == 8){
								var _rowData = this.getRowData(rowid);
								if(_rowData.url != null && _rowData.url != ""){
									//在新窗口打开链接
									window.open(_rowData.url);
									//在本窗口打开链接
//								window.location.href = _rowData.url;
								}
							}
						}
					}
				}
			}));
			this.renderViews("#grid_content");
	        this.getView("#grid_content").on("viewRenderAfter", function() {
			});
	    },
	});
	return mainView;
});
